#!/bin/bash

read -p "请输入要查询的PID: " pid

process_info=$(ps -o pid= -o comm= -o user= -o %cpu= -o %mem= -o start= -o time= -o stat= -o vsz= -o rss= -p "$pid")

if [ -z "$process_info" ]; then
    echo "该PID不存在！！"
    exit
fi

read -r process_pid process_command process_user process_cpu process_mem process_start process_time process_stat process_vsz process_rss <<< "$process_info"

echo -e "\e[32m--------------------------------\e[0m"
echo "进程PID: $process_pid"
echo "进程命令：$process_command"
echo "进程所属用户: $process_user"
echo "CPU占用率：$process_cpu%"
echo "内存占用率：$process_mem%"
echo "进程开始运行的时间：$process_start"
echo "进程运行的时间：$process_time"
echo "进程状态：$process_stat"
echo "进程虚拟内存：$process_vsz"
echo "进程共享内存：$process_rss"
echo -e "\e[32m--------------------------------\e[0m"